package com.itheima.d11_api_objects;

import com.itheima.d10_api_object.bean.User;

import java.util.Objects;

public class Test {
    public static void main(String[] args) {
        // 目标：掌握Objects类提供的常用方法。
        String s1 = null;
        String s2 = "itheima";

        /*if (s1!=null) {
            System.out.println(s1.equals(s2));
        }*/
        //避免空指针异常比较两个对象是否相同
        boolean equals = Objects.equals(s1, s2);
        System.out.println("equals = " + equals);

        User u1 = null;
        User u2 = new User();
        System.out.println(u1.equals(u2));//有空指针异常风险
        System.out.println(Objects.equals(u1,u2));


        //判断是否为空
        System.out.println(Objects.isNull(s1));//true
        System.out.println(Objects.isNull(s2));//false

        //判断不为空
        System.out.println(Objects.nonNull(s1));//false
        System.out.println(Objects.nonNull(s2));//true
    }


}
